#include<iostream>
#include<fstream>
#include<string.h>
#include<sstream>
#include<limits>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::getline;

void checktstdin(std::istream & ihs)
{
    cout<<"good"<<ihs.good()<<endl;
    cout<<"faile"<<ihs.fail()<<endl;
    cout<<"eof"<<ihs.eof()<<endl;
    cout<<"bad"<<ihs.bad()<<endl;
}

void readin(std::istream & ihs,string & column)
{
    while(ihs>>column,!ihs.eof())
    {
        if(ihs.bad())
        {
            cout<<"istream broken"<<endl;
        }
        else if (ihs.fail())
        {
            ihs.clear();
            ihs.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
            cout<<"需要重新输入"<<endl;
        }
        else if(ihs)
        {
            cout<<column<<endl;
        }
    }
    cout<<"by hang"<<endl;
}

void readbyline(std::istream &fst,string & column)
{
    while(getline(fst,column))
    {
        cout<<column<<endl;
    }
    cout<<"by line"<<endl;

}

int main(int argc,char* argv[])
{
    string column;
    std::ifstream ifs("a.txt");
    readin(ifs,column);
    /* readbyline(ifs,column); */
    cout<<endl;
    checktstdin(cin);
    cout<<endl;

    ifs.clear();
    column.clear();

    ifs.seekg(0,std::ios::beg);
    readbyline(ifs,column);
    /* readin(ifs,column); */
    cout<<endl;
    checktstdin(cin);
    cout<<endl;

    cout<<"输入相关值"<<endl;
    readin(cin,column);
    ifs.close();

}


